package chessGame.piece;

import chessGame.Board;
import chessGame.annotation.PieceInfo;
import chessGame.move.BishopMoveStrategy;
import chessGame.utils.MoveUtils;
import chessLib.Position;

import java.util.Collection;
import java.util.HashSet;
import java.util.Set;

/**
 * @BelongsProject: chessGame
 * @BelongsPackage: chessGame
 * @CreateTime: 2025-09-30  09:21
 * @Description: TODO
 * @Version: 1.0
 */
@PieceInfo(value = "Bishop")
public class Bishop extends Piece{
    private final BishopMoveStrategy bishopMove;

    public Bishop() {
        super("Bishop");
        this.bishopMove = new BishopMoveStrategy();
    }
    public Bishop(String pieceName) {
        super(pieceName);
        this.bishopMove = new BishopMoveStrategy();
    }


    //计算本次移动中所有可能存在的点位
    /*@Override
    public Set<Position> getValidMoves(Position currentPosition, Board board) {
        Set<Position> validMoves = new HashSet<>();
        int row = currentPosition.getRow();
        int col = currentPosition.getCol();

        int[][] directions = {{-1, -1}, {-1, 1}, {1, -1}, {1, 1}};

        for (int[] direction : directions) {
            int dRow = direction[0];
            int dCol = direction[1];

            // 朝这个方向移动，直到我们到达棋盘边界
            for (int i = 1; ; i++) {
                int newRow = row + i * dRow;
                int newCol = col + i * dCol;

                // 检查新位置是否在棋盘边界内
                if (newRow >= 1 && newRow <= 8 && newCol >= 1 && newCol <= 8) {
                    Position newPosition = new Position(newRow, newCol);

                    //如果位置被占用，停止在这个方向上的移动
                    if (board.isOccupied(newPosition)) {
                        break;
                    }
                    validMoves.add(newPosition);
                } else {
                    // 超过棋盘的边界
                    break;
                }
            }
        }

        return validMoves;
    }*/

    @Override
    public Set<Position> getValidMoves(Position currentPosition, Board board) {
        Collection<Position> positions = bishopMove.validMovesFor(currentPosition);
        return MoveUtils.deduplication(positions, board);
    }

    @Override
    public String getName() {
        return "Bishop";
    }
}
